package com.jianlong.media;

import java.io.File;

import javax.media.Manager;
import javax.media.Player;

public class Sound {
	/**
	 * 
	 */
	private Player player;
	private File file;

	public Sound() {
		openFile();
		createPlayer();
		try {
			Thread.sleep(3000);
			removePreviousPlayer();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	private void openFile() {
		file = new File(
				"G:\\work_place\\2009_11_09_09_51\\src\\org\\horse\\ygj\\job\\system.wav");
	}

	@SuppressWarnings("deprecation")
	private void createPlayer() {
		if (file == null) {
			return;
		}
		removePreviousPlayer();
		try {
			player = Manager.createPlayer(file.toURL());
			player.start();
		} catch (Exception e) {

		}
	}

	private void removePreviousPlayer() {
		if (player == null) {
			return;
		}
		player.close();
	}

}
